/*<div class="bx-list-box" id="widget">

</div>*/

/*
	recommend 推荐位数据 array
	ContentList 列表数据 array
*/
// 定义一个全局的
var widget2Config = {};

function widget2Init(ContentList,currentPage){

	widget2Config.ContentList = ContentList;
	//获取列表内容个数
	var listLength = ContentList.length;
	//获取当前page
	widget2Config.page = currentPage?currentPage:0;
	//获取总页数
	widget2Config.totalPage = Math.ceil(listLength / 12);
	// 获取当前 列表数组
	var currentList = ContentList.slice(widget2Config.page * 12, widget2Config.page * 12 + 12);

	var leftSrc = widget2Config.page == 0?'../images/home/zuojiantou_1.png':'../images/home/xiangzuo.png';
	var rightSrc = widget2Config.page == widget2Config.totalPage-1?'../images/home/youjiantou_1.png':'../images/home/xiangyou.png';

	var str = "\
	<div class='list-box-widget' id='widgetTop'>\
		<div class='left_arrow'>\
			<img src='"+leftSrc+"'>\
		</div>\
		<div class='list-box-content' id='widgetContent'>\
			<ul id='widgetContentul' style='width: 100%;height: 100%;overflow: hidden;'>\
				"+createLi(currentList)+"\
			</ul>\
		</div>\
		<div class='right_arrow'>\
			<img src='"+rightSrc+"'>\
		</div>\
	</div>\
	<div class='list-box-back'>\
		<span> "+(widget2Config.page+1)+" / "+widget2Config.totalPage+" </span>\
		<img src='../images/home/return.png'>\
	</div>"

	$("#widget2").html(str);

	setFocus("widgetContentul",0);
}


function createLi(dataArray){

	var str = "";

	for(var i = 0; i < dataArray.length; i++){

		str += "<li class='ver_box_style' tabindex='-1' style='float: left;width: 25%;height: 33.333%;overflow: hidden;'><img src='"+dataArray[i].image+"'><p class='style1-con-des'>"+dataArray[i].description+" <span>"+dataArray[i].date+"</span></p></li>"
	}
	
	return str;
}

function widgetTop(event,dom,dir){
	switch(event){
		case "MoveFocus":
			switch(dir){
				case "up":
					onSelect(event,dom.parent(),dir);
					break;
				case "down":
					onSelect(event,dom.parent(),dir);
					break;
				case "left":
					onSelect(event,dom.parent(),dir);
					break;
				case "right":
					onSelect(event,dom.parent(),dir);
					break;
			}
			break;
		case "Back":
			onSelect(event,dom.parent());
			break;
		case "Click":
			break;
	}
}

function widgetContent(event,dom,dir){
	switch(event){
		case "MoveFocus":
			switch(dir){
				case "up":

					onSelect(event,dom.parent(),dir);
					break;
				case "down":
					onSelect(event,dom.parent(),dir);
					break;
				case "left":

					if(widget2Config.page == 0){
						onSelect(event,dom.parent(),dir);
					}else{
						widget2Config.page = widget2Config.page - 1;
						widget2Init(widget2Config.ContentList,widget2Config.page);
					}

					break;
				case "right":

					
					if(widget2Config.page == widget2Config.totalPage-1){
						onSelect(event,dom.parent(),dir);
					}else{
						widget2Config.page = widget2Config.page + 1;
						widget2Init(widget2Config.ContentList,widget2Config.page);
					}

					break;
			}
			break;
		case "Back":
			onSelect(event,dom.parent());
			break;
		case "Click":
			break;
	}
}

function widgetContentul(event,dom,dir){
	switch(event){
		case "MoveFocus":
			if(ulIsBorder(dom,dir,4,12)){
				onSelect(event,dom.parent().parent(),dir);
			}
			break;
		case "Back":
			onSelect(event,dom.parent());
			break;
		case "Click":
			break;
	}
}
function widget2(event,dom,dir){
	switch(event){
		case "MoveFocus":
			switch(dir){
				case "up":
					onSelect(event,dom.parent(),dir);
					break;
				case "down":
					onSelect(event,dom.parent(),dir);
					break;
				case "left":
					onSelect(event,dom.parent(),dir);
					break;
				case "right":
					onSelect(event,dom.parent(),dir);
					break;
			}
			break;
		case "Back":
			onSelect(event,dom.parent());
			break;
		case "Click":
			break;
	}
}
